package com.ruoyi.web.controller.exam;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.DocumentCategory;
import com.ruoyi.exam.service.IDocumentCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档分类树状结构Controller
 * 
 * @author xiayuan
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/exam/category")
public class DocumentCategoryController extends BaseController
{
    @Autowired
    private IDocumentCategoryService documentCategoryService;

    /**
     * 查询文档分类树状结构列表
     */
    @PreAuthorize("@ss.hasPermi('exam:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocumentCategory documentCategory)
    {
        startPage();
        List<DocumentCategory> list = documentCategoryService.selectDocumentCategoryList(documentCategory);
        return getDataTable(list);
    }

    /**
     * 导出文档分类树状结构列表
     */
    @PreAuthorize("@ss.hasPermi('exam:category:export')")
    @Log(title = "文档分类树状结构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DocumentCategory documentCategory)
    {
        List<DocumentCategory> list = documentCategoryService.selectDocumentCategoryList(documentCategory);
        ExcelUtil<DocumentCategory> util = new ExcelUtil<DocumentCategory>(DocumentCategory.class);
        util.exportExcel(response, list, "文档分类树状结构数据");
    }

    /**
     * 获取文档分类树状结构详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(documentCategoryService.selectDocumentCategoryById(id));
    }

    /**
     * 新增文档分类树状结构
     */
    @PreAuthorize("@ss.hasPermi('exam:category:add')")
    @Log(title = "文档分类树状结构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentCategory documentCategory)
    {
        return toAjax(documentCategoryService.insertDocumentCategory(documentCategory));
    }

    /**
     * 修改文档分类树状结构
     */
    @PreAuthorize("@ss.hasPermi('exam:category:edit')")
    @Log(title = "文档分类树状结构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentCategory documentCategory)
    {
        return toAjax(documentCategoryService.updateDocumentCategory(documentCategory));
    }

    /**
     * 删除文档分类树状结构
     */
    @PreAuthorize("@ss.hasPermi('exam:category:remove')")
    @Log(title = "文档分类树状结构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(documentCategoryService.deleteDocumentCategoryByIds(ids));
    }
}
